package com.qing.dish;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Demo {

	private static List<Dish> menu= Arrays.asList(
			new Dish("黄焖鸡米饭",false,15,"肉"),
			new Dish("水煮鱼",true,12,"鱼"),
			new Dish("酸菜鱼",false,20,"鱼"),
			new Dish("脆皮鸡米饭",false,18,"米饭"),
			new Dish("麻辣香锅",true,32,"米饭"),
			new Dish("鸡公煲",false,20,"肉"),
			new Dish("汉堡王",true,100,"米饭"),
			new Dish("至尊牛排",false,20,"肉"),
			new Dish("蛋炒饭",true,12,"素"),
			new Dish("咖喱",false,29,"米饭"),
			new Dish("炒白菜",false,8,"素"),
			new Dish("炒萝卜",false,9,"素"),
			new Dish("烤肉",true,50,"肉")
	);

/*	public static void main(String[] args) {
		List<String> list=menu.stream(). //从menu获取流
				filter(d->d.getCalories()<20) //建立操作流水线，首先选出热量<20的
				.sorted(Comparator.comparing(Dish::getCalories))//排序
				.map(Dish::getName) //获取菜品名
				.limit(6) //只获取前6个
				.collect(Collectors.toList());//将结果保存到另一个list中



        List<String> list1=menu.stream(). //从menu获取流
		filter(d->{
			System.out.println("d1:"+d.toString());
			return d.getCalories()<20;}).sorted(Comparator.comparing(Dish::getCalories))//排序 //建立操作流水线，首先选出热量<20的
				.map(d->{
					System.out.println("d2:"+d.toString());
					return  d.getName();
				})
				.collect(Collectors.toList());//将结果保存到另一个list中

        System.out.println("------------------------------------");
        List<String> list2=menu.stream().
        sorted(Comparator.comparing(Dish::getCalories))
                .takeWhile(d->{
			System.out.println("d1:"+d.toString());
			return d.getCalories()<20;}) //建立操作流水线，首先选出热量<20的
				.map(d->{
					System.out.println("d2:"+d.toString());
					return  d.getName();
				}) //获取菜品名
				.collect(Collectors.toList());//将结果保存到另一个list中

        System.out.println("------------------------------------");
        List<String> list3=menu.stream().
                sorted(Comparator.comparing(Dish::getCalories))
                .takeWhile(d->{
            System.out.println("d1:"+d.toString());
            return d.getCalories()<20;}) //建立操作流水线，首先选出热量<20的
                .map(d->{
                    System.out.println("d2:"+d.toString());
                    return  d.getName();
                }).skip(4) //获取菜品名
                .collect(Collectors.toList());//将结果保存到另一个list中

        System.out.println(list1);
        System.out.println(list2);
        System.out.println(list3);
	}*/
}
